package com.nand.module.function.ui;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.espresso.core.internal.deps.guava.base.Joiner;

import com.alibaba.fastjson.JSON;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.huantansheng.easyphotos.EasyPhotos;
import com.huantansheng.easyphotos.callback.SelectCallback;
import com.huantansheng.easyphotos.models.album.entity.Photo;
import com.lzy.okgo.model.HttpParams;
import com.nand.library.base.base.BaseActivity;
import com.nand.library.base.bean.ResponseBean;
import com.nand.library.base.http.Callback;
import com.nand.library.base.http.MyCallback;
import com.nand.library.base.http.OkGoUtils;
import com.nand.library.base.utils.GlideEngine;
import com.nand.library.base.utils.ObjectUtils;
import com.nand.library.base.utils.SpUtils;
import com.nand.library.zxing.activity.CaptureActivity;
import com.nand.library.zxing.activity.CodeUtils;
import com.nand.module.function.R;
import com.nand.module.function.adapter.SearchAdapter;
import com.nand.module.function.bean.CheckItemsBean;
import com.nand.module.function.bean.DepartBean;
import com.nand.module.function.bean.EpairDetailsBean;
import com.nand.module.function.bean.EqDetailInfoBean;
import com.nand.module.function.bean.IdBean;
import com.nand.module.function.bean.MainPersonBean;
import com.nand.module.function.bean.ManageBean;
import com.nand.module.function.bean.MmhitchListBean;
import com.nand.module.function.bean.NumberBean;
import com.nand.module.function.constant.URL;
import com.nand.module.function.utils.LogUtils;
import com.nand.module.function.utils.ToolUtils;
import com.nand.module.function.view.CommonPopupWindow;
import com.nand.module.function.view.ImageActivity;
import com.nand.module.function.view.WheelView;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * created by 86185
 * on 2019/12/24
 */
public class EpairDetailsActivity extends BaseActivity implements View.OnClickListener {

    private static final int EPAIR_ADD = 101;  //新增异常
    private static final int EPAIR_DISPOSE = 102; //异常处理
    private static final int EPAIR_AFFIRM = 103;  //确认异常
    private static final int REJECT_DISPOSE = 104; //驳回处理
    private static final int EPAIR_DETAILS = 105;//中止异常
    private TextView mTvScpc, mTvZzpbh, mTvSbbh, mTvSbmc, mTvCpfl, mTvGx, mTvYclx, mTvYcmc, mTvYcdj, mTvClr, mTvYcms, mTvConfirm, mTvConfirm2, mTvClff, mTvFfms, mTvYcyy, mTvGjjy, mTvBhyy, mTvCxsj;
    private EditText mEtCxsj, mEtBhyy, mEtGjjy, mEtYcyy, mEtClff, mEtSbbh, mEtYcms, mEtZzpbh, mEtScpc;
    private ImageView mIvScpc, mIvZzpbh, mIvSbbh, mIvClr, mIvYcdj, mIvYcmc, mIvYclx, mIvCpfl, mIvGx;
    private RecyclerView mRecycler, mRecycler2;
    private static final int REQUEST_CODE_SCPC = 1001;
    private static final int REQUEST_CODE_ZZPBH = 1002;
    private static final int REQUEST_CODE_SBBH = 1003;
    private CommonPopupWindow window;
    private WheelView mWheelCpfl, mWheelGx, mWheelYclx, mWheelBm, mWheelYCdj, mWheelClr;
    private int code;
    private String oid;
    private String abnormalId;
    private String equipId;
    private int optimisticLockField;
    private PublishImgAdapter imgAdapter;
    private ArrayList<String> imgPathList = new ArrayList<>();
    private HttpParams params;
    private ShowImgAdapter imgAdapter2;
    private String productType;
    private List<String> imageList;
    private ArrayList<String> mData;
    private TextView mTvPhoto;
    private RecyclerView mRecyclerView;
    private SearchAdapter mAdapter;
    private int prodAnoTGrand;
    private int recyviewShow = 1;
    private ArrayList<File> files;
    private List<String> imagePath;
    private String str = "";
    private LinearLayout mLlClff, mLlYcyy, mLlGjjy, mLlBhyy, mLlCxsj;
    private int userId;
    private TextView mTvConfirm7;
    private String type;

    @Override
    protected int initLayout() {
        return R.layout.activity_epair_details;
    }

    @Override
    protected void initView() {
        code = getIntent().getIntExtra("code", 5);
        abnormalId = getIntent().getStringExtra("abnormalId");
        userId = SpUtils.readInt(this, "userId", 0);
        mTvScpc = findViewById(R.id.tv_scpc);
        mTvZzpbh = findViewById(R.id.tv_zzpbh);
        mTvSbbh = findViewById(R.id.tv_sbbh);
        mTvSbmc = findViewById(R.id.tv_sbmc);
        mTvCpfl = findViewById(R.id.tv_cpfl);
        mTvGx = findViewById(R.id.tv_gx);
        mTvYclx = findViewById(R.id.tv_yclx);
        mTvYcmc = findViewById(R.id.tv_ycmc);
        mTvYcdj = findViewById(R.id.tv_ycdj);
        mTvClr = findViewById(R.id.tv_clr);
        mTvYcms = findViewById(R.id.tv_ycms);
        mTvClff = findViewById(R.id.tv_clff);
        mTvYcyy = findViewById(R.id.tv_ycyy);
        mTvGjjy = findViewById(R.id.tv_gjjy);
        mTvBhyy = findViewById(R.id.tv_bhyy);
        mTvCxsj = findViewById(R.id.tv_cxsj);
        mEtScpc = findViewById(R.id.et_scpc);
        mEtZzpbh = findViewById(R.id.et_zzpbh);
        mEtSbbh = findViewById(R.id.et_sbbh);
        mEtYcms = findViewById(R.id.et_ycms);
        mEtClff = findViewById(R.id.et_clff);
        mEtYcyy = findViewById(R.id.et_ycyy);
        mEtGjjy = findViewById(R.id.et_gjjy);
        mEtBhyy = findViewById(R.id.et_bhyy);
        mEtCxsj = findViewById(R.id.et_cxsj);
        mIvScpc = findViewById(R.id.iv_scpc);
        mIvZzpbh = findViewById(R.id.iv_zzpbh);
        mIvSbbh = findViewById(R.id.iv_sbbh);
        mRecycler = findViewById(R.id.recycler);
        mRecycler2 = findViewById(R.id.recycler2);
        mTvConfirm = findViewById(R.id.tv_epair_confirm);
        mTvConfirm2 = findViewById(R.id.tv_epair_confirm2);
        mTvPhoto = findViewById(R.id.tv_photo);
        mEtSbbh.addTextChangedListener(watcher);
        mIvScpc.setOnClickListener(this);
        mIvZzpbh.setOnClickListener(this);
        mIvSbbh.setOnClickListener(this);
        mIvCpfl = findViewById(R.id.iv_cpfl);
        mIvGx = findViewById(R.id.iv_gx);
        mIvYclx = findViewById(R.id.iv_yclx);
        mIvYcmc = findViewById(R.id.iv_ycmc);
        mIvYcdj = findViewById(R.id.iv_ycdj);
        mIvClr = findViewById(R.id.iv_clr);
        mLlClff = findViewById(R.id.ll_clff);
        mLlYcyy = findViewById(R.id.ll_ycyy);
        mLlGjjy = findViewById(R.id.ll_gjjy);
        mLlBhyy = findViewById(R.id.ll_bhyy);
        mLlCxsj = findViewById(R.id.ll_cxsj);


        imagePath = new ArrayList();
        mRecyclerView = findViewById(R.id.rv_list);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new SearchAdapter(R.layout.item_text_layout);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                String equipID = dataList.get(position).getEquipID();
                recyviewShow = 0;
                mEtSbbh.setText(equipID);

                // mRecyclerView.setVisibility(View.GONE);
                HttpParams params1 = new HttpParams();
                params1.put("equipID", equipID);
                OkGoUtils.getInstance().post(EpairDetailsActivity.this, URL.GET_DETAIL_INFO, params1, 1, false, mCallback1);
            }
        });

        mRecycler2.setLayoutManager(new

                LinearLayoutManager(this));
        GridLayoutManager layoutManager2 = new GridLayoutManager(this, 3);
        mRecycler2.setLayoutManager(layoutManager2);
        imgAdapter2 = new ShowImgAdapter(this);
        mRecycler.setLayoutManager(new LinearLayoutManager(this));
        GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
        mRecycler.setLayoutManager(layoutManager);
        imgAdapter = new PublishImgAdapter(this);
        imgAdapter.setImgItemClickListener(new PublishImgAdapter.ImgItemClick() {
            @Override
            public void itemClick(String url, int position) {
            }

            @Override
            public void lastItemClick() {
                // 添加图片
                EasyPhotos.createAlbum(EpairDetailsActivity.this, true, GlideEngine.getInstance())
                        .setFileProviderAuthority("com.nand.library.base")
                        .setCount(3)
                        .start(new SelectCallback() {
                            @Override
                            public void onResult(ArrayList<Photo> photos, boolean isOriginal) {
                                for (int i = 0; i < photos.size(); i++) {
                                    addImage(photos.get(i).path);
                                }


                            }
                        });

            }

            @Override
            public void delImg(String url, int position) {
                if (imgAdapter != null) {
                    if (imgPathList.remove(url)) {
                        imgAdapter.setData(imgPathList);
                    }
                    imagePath.remove(position);
                }
            }
        });
        imgAdapter2.setImgItemClickListener(new ShowImgAdapter.ImgItemClick() {
            @Override
            public void itemClick(String url, int position) {
                Intent intent1 = new Intent(mContext, ImageActivity.class);
                intent1.putStringArrayListExtra(ImageActivity.IMG_LIST, mData);
                startActivity(intent1);
            }

            @Override
            public void lastItemClick() {

            }

            @Override
            public void delImg(String url) {

            }
        });
        mRecycler.setAdapter(imgAdapter);
        mRecycler2.setAdapter(imgAdapter2);
        switch (code) {
            case EPAIR_ADD:
                mActionBar().setCenterText("新增异常");
                mEtClff.setVisibility(View.GONE);
                mEtYcyy.setVisibility(View.GONE);
                mEtGjjy.setVisibility(View.GONE);
                mEtBhyy.setVisibility(View.GONE);
                mEtCxsj.setVisibility(View.GONE);
                mTvConfirm.setText("提交");
                mTvConfirm2.setVisibility(View.GONE);
                mIvCpfl.setVisibility(View.VISIBLE);
                mIvGx.setVisibility(View.VISIBLE);
                mIvYclx.setVisibility(View.VISIBLE);
                mIvYcmc.setVisibility(View.VISIBLE);
                mIvYcdj.setVisibility(View.VISIBLE);
                mIvClr.setVisibility(View.VISIBLE);
                mLlClff.setVisibility(View.GONE);
                mLlYcyy.setVisibility(View.GONE);
                mLlGjjy.setVisibility(View.GONE);
                mLlBhyy.setVisibility(View.GONE);
                mLlCxsj.setVisibility(View.GONE);
                findViewById(R.id.view_line1).setVisibility(View.GONE);
                findViewById(R.id.view_line2).setVisibility(View.GONE);
                findViewById(R.id.view_line3).setVisibility(View.GONE);
                findViewById(R.id.view_line4).setVisibility(View.GONE);
                findViewById(R.id.view_line5).setVisibility(View.GONE);
                findViewById(R.id.ll_cpfl).setOnClickListener(this);
                findViewById(R.id.ll_gx).setOnClickListener(this);
                findViewById(R.id.ll_yclx).setOnClickListener(this);
                findViewById(R.id.ll_ycmc).setOnClickListener(this);
                findViewById(R.id.ll_ycdj).setOnClickListener(this);
                findViewById(R.id.ll_clr).setOnClickListener(this);
                mTvPhoto.setText("上传照片：");
                OptionsPicker();
                break;
            case EPAIR_DISPOSE:
                mRecycler.setVisibility(View.GONE);
                mActionBar().setCenterText("异常处理");
                mEtScpc.setVisibility(View.INVISIBLE);
                mEtZzpbh.setVisibility(View.INVISIBLE);
                mEtSbbh.setVisibility(View.INVISIBLE);
                mIvScpc.setVisibility(View.GONE);
                mIvZzpbh.setVisibility(View.GONE);
                mIvSbbh.setVisibility(View.GONE);
                findViewById(R.id.view_line5).setVisibility(View.GONE);
                mLlCxsj.setVisibility(View.GONE);
                mEtCxsj.setVisibility(View.GONE);
                mEtYcms.setVisibility(View.GONE);
                mTvPhoto.setText("照片查看：");
                mTvConfirm.setText("处理");
                mTvConfirm2.setText("驳回");
                HttpParams params = new HttpParams();
                params.put("abnormalId", abnormalId); //工序编号
                OkGoUtils.getInstance().post(this, URL.ABNORMA_VIEW, params, 6, true, mCallback6);
                break;
            case EPAIR_AFFIRM:
                mRecycler.setVisibility(View.GONE);
                mActionBar().setCenterText("异常确认");
                mEtScpc.setVisibility(View.INVISIBLE);
                mEtZzpbh.setVisibility(View.INVISIBLE);
                mEtSbbh.setVisibility(View.INVISIBLE);
                mIvScpc.setVisibility(View.GONE);
                mIvZzpbh.setVisibility(View.GONE);
                mIvSbbh.setVisibility(View.GONE);
                mEtYcms.setVisibility(View.GONE);
                mEtClff.setVisibility(View.GONE);
                mEtYcyy.setVisibility(View.GONE);
                mEtGjjy.setVisibility(View.GONE);
                mEtBhyy.setVisibility(View.GONE);

                findViewById(R.id.view_line5).setVisibility(View.GONE);
                mLlBhyy.setVisibility(View.GONE);
                mTvPhoto.setText("照片查看：");
                mTvConfirm.setText("确认");
                mTvConfirm2.setVisibility(View.GONE);
                HttpParams params2 = new HttpParams();
                params2.put("abnormalId", abnormalId); //工序编号
                OkGoUtils.getInstance().post(this, URL.ABNORMA_VIEW, params2, 6, true, mCallback6);
                break;
            case REJECT_DISPOSE:
                mActionBar().setCenterText("驳回处理");
                mEtClff.setVisibility(View.GONE);
                mEtYcyy.setVisibility(View.GONE);
                mEtGjjy.setVisibility(View.GONE);
                mEtBhyy.setVisibility(View.GONE);
                mEtCxsj.setVisibility(View.GONE);
                mTvConfirm.setText("提交");
                mTvConfirm2.setText("中止");
                mIvCpfl.setVisibility(View.VISIBLE);
                mIvGx.setVisibility(View.VISIBLE);
                mIvYclx.setVisibility(View.VISIBLE);
                mIvYcmc.setVisibility(View.VISIBLE);
                mIvYcdj.setVisibility(View.VISIBLE);
                mIvClr.setVisibility(View.VISIBLE);

                mLlClff.setVisibility(View.GONE);
                mLlYcyy.setVisibility(View.GONE);
                mLlGjjy.setVisibility(View.GONE);
                mLlCxsj.setVisibility(View.GONE);
                findViewById(R.id.view_line2).setVisibility(View.GONE);
                findViewById(R.id.view_line3).setVisibility(View.GONE);
                findViewById(R.id.view_line4).setVisibility(View.GONE);
                findViewById(R.id.view_line5).setVisibility(View.GONE);
                findViewById(R.id.ll_cpfl).setOnClickListener(this);
                findViewById(R.id.ll_gx).setOnClickListener(this);
                findViewById(R.id.ll_yclx).setOnClickListener(this);
                findViewById(R.id.ll_ycmc).setOnClickListener(this);
                findViewById(R.id.ll_ycdj).setOnClickListener(this);
                findViewById(R.id.ll_clr).setOnClickListener(this);
                mTvPhoto.setText("上传照片：");
                HttpParams params4 = new HttpParams();
                params4.put("abnormalId", abnormalId); //工序编号
                OkGoUtils.getInstance().post(this, URL.ABNORMA_VIEW, params4, 6, true, mCallback6);
                OptionsPicker();
                break;
            case EPAIR_DETAILS:
                mRecycler.setVisibility(View.GONE);
                mActionBar().setCenterText("异常详情");
                mEtScpc.setVisibility(View.INVISIBLE);
                mEtZzpbh.setVisibility(View.INVISIBLE);
                mEtSbbh.setVisibility(View.INVISIBLE);
                mIvScpc.setVisibility(View.GONE);
                mIvZzpbh.setVisibility(View.GONE);
                mIvSbbh.setVisibility(View.GONE);
                mIvCpfl.setVisibility(View.GONE);
                mEtYcms.setVisibility(View.GONE);
                mEtClff.setVisibility(View.GONE);
                mEtYcyy.setVisibility(View.GONE);
                mEtGjjy.setVisibility(View.GONE);
                mEtBhyy.setVisibility(View.GONE);
                mEtCxsj.setVisibility(View.GONE);
                mTvConfirm.setVisibility(View.GONE);
                mTvConfirm2.setVisibility(View.GONE);
                mTvPhoto.setText("照片查看：");
                HttpParams params3 = new HttpParams();
                params3.put("abnormalId", abnormalId); //工序编号
                OkGoUtils.getInstance().post(this, URL.ABNORMA_VIEW, params3, 6, true, mCallback6);
                break;
            default:
                break;
        }

    }

    private void addImage(final String imageUrl) {

        files = new ArrayList<>();

        File file = new File(imageUrl);
        files.add(file);

        OkGoUtils.getInstance().upload(this, URL.UPLOAD_PICTURES, files, new MyCallback() {
            @Override
            public void onSuccess(ResponseBean response, int id) {
                if (response.getCode() == 200) {
                    LogUtils.e("1ac===========" + response.getDataInfo().toString());
                    String s = response.getDataInfo().toString();
                    String substring = s.substring(2, s.length() - 2);
                    imgPathList.add(imageUrl);
                    imagePath.add(substring);
                    imgAdapter.setData(imgPathList);
                } else {
                    showToast(response.getMsg());
                }
            }

            @Override
            public void onError(Throwable e, int id) {
                showToast("上传失败");
            }
        });
    }

    private TextWatcher watcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() > 0) {
                getSearchInfo(editable.toString(), 0);
            }
        }
    };

    private List<NumberBean.DataListBean> dataList;
    private List<String> list = new ArrayList<>();

    private void getSearchInfo(String text, final int type) {
        HttpParams params = new HttpParams();
        params.put("equipID", text);
        params.put("current", "1");
        params.put("size", "10");
        OkGoUtils.getInstance().post(this, URL.GET_EQUIPMENT_INFO, params, 0, false, new MyCallback() {
            @Override
            public void onSuccess(ResponseBean response, int id) {
                if (response.getCode() == 200) {
                    String dataInfo = response.getDataInfo().toString();
                    LogUtils.e("ab=======" + dataInfo);
                    NumberBean bean = JSON.parseObject(dataInfo, NumberBean.class);
                    dataList = bean.getDataList();
                    list.clear();
                    for (int i = 0; i < dataList.size(); i++) {
                        list.add(dataList.get(i).getEquipID());
                    }
                    mAdapter.replaceData(list);
                } else {
                    showToast(response.getMsg());
                }
                if (list.size() >= 0) {
                    // mShowTips.setVisibility(View.GONE);
                    if (0 == recyviewShow) {
                        mRecyclerView.setVisibility(View.GONE);
                        recyviewShow = 1;
                    } else {
                        mRecyclerView.setVisibility(View.VISIBLE);
                    }


                    if (1 == type) {
                        Intent intent = new Intent();
                        Bundle bundle = new Bundle();
                        bundle.putInt(CodeUtils.RESULT_TYPE, CodeUtils.RESULT_SUCCESS);
                        bundle.putString(CodeUtils.RESULT_STRING, dataList.get(0).getEquipID());
                        bundle.putString(CodeUtils.RESULT_STRING2, dataList.get(0).getOid());
                        intent.putExtras(bundle);
                        EpairDetailsActivity.this.setResult(RESULT_OK, intent);
                        EpairDetailsActivity.this.finish();
                    }

                } else {
                    //mShowTips.setVisibility(View.VISIBLE);
                    mRecyclerView.setVisibility(View.GONE);
                }
            }

            @Override
            public void onError(Throwable e, int id) {

            }
        });
    }

    /**
     * 请求返回的处理
     */
    private MyCallback mCallback6 = new MyCallback() {
        @Override
        public void onSuccess(ResponseBean response, int id) {
            if (response.getCode() == 200) {
                String data = response.getDataInfo().toString();
                LogUtils.e("aaaaaaaaaaaaaa===" + data);
                EpairDetailsBean bean = JSON.parseObject(data, EpairDetailsBean.class);
                switch (code) {
                    case EPAIR_DISPOSE:
                        mTvScpc.setText(bean.getProBatchId());
                        mTvZzpbh.setText(bean.getProductId());
                        mTvSbbh.setText(bean.getEquipNode());
                        mTvSbmc.setText(bean.getEquipName());
                        productType = bean.getProductType();
                        mTvCpfl.setText(cpflStrting[Integer.parseInt(productType)]);
                        mTvGx.setText(bean.getProcessContent());
                        mTvYclx.setText(bean.getProdAnoType());
                        mTvYcmc.setText(bean.getProdAnoTName());
                        prodAnoTGrand = bean.getProdAnoTGrand();
                        if (0 == prodAnoTGrand) {
                            mTvYcdj.setText("轻微");
                        } else if (1 == prodAnoTGrand) {
                            mTvYcdj.setText("一般");
                        } else {
                            mTvYcdj.setText("严重");
                        }

                        mTvClr.setText(bean.getUserName());
                        mTvYcms.setText(bean.getProdAnoTDetail());
                        abnormalId = bean.getAbnormalId();
                        equipId = bean.getEquipId();
                        optimisticLockField = bean.getOptimisticLockField();
                        EpairDetailsActivity.this.productType = bean.getProductType();

                        imageList = bean.getImageList();
                        if ("".equals(imageList) || null == imageList) {
                            return;
                        }

                        mData = new ArrayList<>();
                        for (int i = 0; i < imageList.size(); i++) {
                            mData.add(0, imageList.get(i));
                        }

                        imgAdapter2.setData(mData);
                        break;
                    case EPAIR_AFFIRM: //异常确认
                        mTvScpc.setText(bean.getProBatchId());
                        mTvZzpbh.setText(bean.getProductId());
                        mTvSbbh.setText(bean.getEquipNode());
                        mTvSbmc.setText(bean.getEquipName());
                        mTvGx.setText(bean.getProcessContent());
                        mTvYclx.setText(bean.getProdAnoType());
                        mTvYcmc.setText(bean.getProdAnoTName());
                        prodAnoTGrand = bean.getProdAnoTGrand();
                        if (0 == prodAnoTGrand) {
                            mTvYcdj.setText("一般");
                        } else {
                            mTvYcdj.setText("严重");
                        }
                        productType = bean.getProductType();
                        mTvCpfl.setText(cpflStrting[Integer.parseInt(productType)]);
                        mTvClr.setText(bean.getUserName());
                        mTvYcms.setText(bean.getProdAnoTDetail());
                        mTvClff.setText(bean.getMethodDescription());
                        mTvYcyy.setText(bean.getProdAnoReason());
                        mTvGjjy.setText(bean.getSuggest());
                        abnormalId = bean.getAbnormalId();
                        equipId = bean.getEquipId();
                        EpairDetailsActivity.this.productType = bean.getProductType();
                        optimisticLockField = bean.getOptimisticLockField();

                        imageList = bean.getImageList();
                        if ("".equals(imageList) || null == imageList) {
                            return;
                        }

                        mData = new ArrayList<>();
                        for (int i = 0; i < imageList.size(); i++) {
                            mData.add(0, imageList.get(i));
                        }

                        imgAdapter2.setData(mData);
                        break;
                    case EPAIR_DETAILS:
                        mTvScpc.setText(bean.getProBatchId());
                        mTvZzpbh.setText(bean.getProductId());
                        mTvSbbh.setText(bean.getEquipNode());
                        mTvSbmc.setText(bean.getEquipName());
                        mTvGx.setText(bean.getProcessContent());
                        mTvYclx.setText(bean.getProdAnoType());
                        mTvYcmc.setText(bean.getProdAnoTName());
                        prodAnoTGrand = bean.getProdAnoTGrand();
                        if (0 == prodAnoTGrand) {
                            mTvYcdj.setText("一般");
                        } else {
                            mTvYcdj.setText("严重");
                        }

                        productType = bean.getProductType();
                        mTvCpfl.setText(cpflStrting[Integer.parseInt(productType)]);
                        mTvClr.setText(bean.getUserName());
                        mTvYcms.setText(bean.getProdAnoTDetail());
                        mTvClff.setText(bean.getMethodDescription());
                        mTvYcyy.setText(bean.getProdAnoReason());
                        mTvGjjy.setText(bean.getSuggest());
                        int lastTime = bean.getLastTime();
                        //String time = ToolUtils.formatDateTime(lastTime);
                        mTvCxsj.setText(lastTime + "分");
                        mTvBhyy.setText(bean.getReasonRejection());
                        abnormalId = bean.getAbnormalId();
                        equipId = bean.getEquipId();
                        EpairDetailsActivity.this.productType = bean.getProductType();

                        imageList = bean.getImageList();
                        if ("".equals(imageList) || null == imageList) {
                            return;
                        }

                        mData = new ArrayList<>();
                        for (int i = 0; i < imageList.size(); i++) {
                            mData.add(0, imageList.get(i));
                        }

                        imgAdapter2.setData(mData);

                        break;

                    case REJECT_DISPOSE: //驳回处理
                        productType = bean.getProductType();
                        mTvCpfl.setText(cpflStrting[Integer.parseInt(productType)]);
                        cpflID = Integer.parseInt(productType);
                        mTvGx.setText(bean.getProcessContent());
                        gxID = Integer.parseInt(bean.getFmmProcessOid());
                        mTvYclx.setText(bean.getProdAnoType());
                        //   yclxID = 0;
                        mTvYcmc.setText(bean.getProdAnoTName());

                        prodAnoTGrand = bean.getProdAnoTGrand();
                        if (0 == prodAnoTGrand) {
                            mTvYcdj.setText("一般");
                        } else {
                            mTvYcdj.setText("严重");
                        }
                        ycdjID = prodAnoTGrand;
                        mTvClr.setText(bean.getUserName());
                        clrID = bean.getUserID();
                        mEtScpc.setText(bean.getProBatchId());
                        mEtZzpbh.setText(bean.getProductId());
                        mEtSbbh.setText(bean.getEquipNode());
                        recyviewShow = 0;
                        mTvSbmc.setText(bean.getEquipName());
                        mEtYcms.setText(bean.getProdAnoTDetail());
                        mTvBhyy.setText(bean.getReasonRejection());

                        abnormalId = bean.getAbnormalId();
                        equipId = bean.getEquipId();
                        optimisticLockField = bean.getOptimisticLockField();
                        EpairDetailsActivity.this.productType = bean.getProductType();

                        imageList = bean.getImageList();
                        if ("".equals(imageList) || null == imageList) {
                            return;
                        }

                        for (int i = 0; i < imageList.size(); i++) {
                            imgPathList.add(imageList.get(i));
                            imgAdapter.setData(imgPathList);
                        }

                        String imagePat = bean.getImagePath();
                        if ("".equals(imagePat) || null == imagePat) {
                            return;
                        }
                        List<String> list = Arrays.asList(imagePat.split(","));
                        for (int i = 0; i < list.size(); i++) {
                            imagePath.add(list.get(i));
                        }


                        break;
                }

            } else {
                showToast(response.getMsg());
            }
        }

        @Override
        public void onError(Throwable e, int id) {
        }
    };

    @Override
    protected boolean isActionBar() {
        return true;
    }

    @Override
    protected void initData() {

    }

    ArrayList<String> mCpflList = new ArrayList<>();
    private int cpflID = 10001;
    private String cpflItem = "";
    ArrayList<IdBean> mGxIdBeanList = new ArrayList<>();
    ArrayList<String> mGxList = new ArrayList<>();
    private int gxID = 10001;
    ArrayList<String> mYclxList = new ArrayList<>();
    private String yclxItem = "";
    private int yclxID = 10001;
    ArrayList<String> mYcdjList = new ArrayList<>();
    private int ycdjID = 10001;
    private List<String> departList = new ArrayList<>();
    private List<List<String>> staffList = new ArrayList<>();
    private List<DepartmentBean> depList = new ArrayList<>();
    private int options;
    private String departOid;
    private String userOid;
    private int clrID = 10001;

    private OptionsPickerView cpflPicker, gxPicker, yclxPicker, ycdjPicker, clrPicker;
    private String[] cpflStrting = new String[]{"电芯", "模组", "PACK"};
    private String[] yclxStrting = new String[]{"质量异常", "设备异常", "原材料异常", "人员异常", "环境异常", "SOP异常"};
    private String[] ycdjString = {"轻微", "一般", "严重"};
    private void initAddBean() {

        for (int i = 0; i < cpflStrting.length; i++) {
            mCpflList.add(cpflStrting[i]);
        }

        for (int i = 0; i < yclxStrting.length; i++) {
            mYclxList.add(yclxStrting[i]);
        }

        for (int i = 0; i < ycdjString.length; i++) {
            mYcdjList.add(ycdjString[i]);
        }
        OkGoUtils.getInstance().post(EpairDetailsActivity.this, URL.GET_DEPART_LIST, null, 1, false, mCallback);
    }




    private void OptionsPicker() {
        initAddBean();
        cpflPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                type = mCpflList.get(options1);
                mTvCpfl.setText(type);
                cpflID = options1;
                cpflItem = type;
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();

        gxPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {

                type = mGxList.get(options1);
                mTvGx.setText(type);
                gxID = mGxIdBeanList.get(options1).getId();
                LogUtils.e("gxid================" + gxID);
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();

        yclxPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                type = mYclxList.get(options1);
                mTvYclx.setText(type);
                yclxItem = type;
                yclxID = options1;
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();

        ycdjPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                type = mYcdjList.get(options1);
                mTvYcdj.setText(type);
                ycdjID = options1;
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();


        clrPicker = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                String tx = departList.get(options1) + "/"
                        + staffList.get(options1).get(options2);

                departOid = depList.get(options1).getOid();
                userOid = depList.get(options1).getUserList().get(options2).getUserId();
                clrID = Integer.parseInt(userOid);
                mTvClr.setText(tx);
            }
        }).setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
            @Override
            public void onOptionsSelectChanged(int options1, int options2, int options3) {
                if (options1 != EpairDetailsActivity.this.options) {
                    EpairDetailsActivity.this.options = options1;
                    EpairDetailsActivity.this.clrPicker.setSelectOptions(options1, 0);
                }
            }
        })
                .setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(14)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(18)//滚轮文字大小
                .setSelectOptions(0, 0)
                .setCyclic(false, false, false)//循环与否
                .build();
    }

    /**
     * 请求返回的处理
     */
    private MyCallback mCallback1 = new MyCallback() {
        @Override
        public void onSuccess(ResponseBean response, int id) {
            if (response.getCode() == 200) {
                String data = response.getDataInfo().toString();
                LogUtils.e("aaa===" + data);
                EqDetailInfoBean bean = JSON.parseObject(data, EqDetailInfoBean.class);
                mTvSbmc.setText(bean.getEquipName());
                oid = bean.getOid();
            } else {
                showToast(response.getMsg());
            }
        }

        @Override
        public void onError(Throwable e, int id) {
        }
    };

    /**
     * 请求返回的处理
     */


    private MyCallback mCallback = new MyCallback() {
        @Override
        public void onSuccess(ResponseBean response, int id) {
            if (response.getCode() == 200) {
                String data = response.getDataInfo().toString();
                LogUtils.e("ac=============" + data);
                switch (id) {
                    case 1: //处理人
                        depList = JSON.parseArray(data, DepartmentBean.class);
                        departList.clear();
                        staffList.clear();
                        for (int i = 0; i < depList.size(); i++) {
                            List<DepartmentBean.UserListBean> userList = depList.get(i).getUserList();
                            ArrayList<String> list = new ArrayList<>();
                            for (int j = 0; j < userList.size(); j++) {
                                list.add(userList.get(j).getUserName());
                            }
                            departList.add(depList.get(i).getDepartName());
                            staffList.add(list);
                        }
                        break;
                    case 2: //工序
                        MmhitchListBean bean = JSON.parseObject(data, MmhitchListBean.class);
                        List<MmhitchListBean.DataListBean> dataList = bean.getDataList();
                        if (0 == dataList.size()) {
                            showToast(cpflItem + "暂无工序，请选择其他产品");
                            return;
                        }
                        mGxList.clear();
                        mGxIdBeanList.clear();
                        for (int i = 0; i < dataList.size(); i++) {
                            IdBean idBean = new IdBean();
                            idBean.setId(dataList.get(i).getOid());
                            idBean.setType(dataList.get(i).getProcessContent());
                            mGxIdBeanList.add(idBean);
                            mGxList.add(dataList.get(i).getProcessContent());
                        }

                        if (ObjectUtils.notEmpty(mGxList)) {
                            gxPicker.setPicker(mGxList);
                            gxPicker.show();
                        }
                        break;
                    case 3:

                        break;
                }

            } else {
                showToast(response.getMsg());
            }


        }

        @Override
        public void onError(Throwable e, int id) {
        }
    };

    public void onClickCode(int request_code) {
        Intent intent = new Intent(EpairDetailsActivity.this, CaptureActivity.class);
        startActivityForResult(intent, request_code);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.iv_scpc) {
            onClickCode(REQUEST_CODE_SCPC);
        } else if (id == R.id.iv_zzpbh) {
            onClickCode(REQUEST_CODE_ZZPBH);
        } else if (id == R.id.iv_sbbh) {
            onClickCode(REQUEST_CODE_SBBH);
        } else if (id == R.id.ll_cpfl) {      /**选择产品分类*/
            if (ObjectUtils.notEmpty(mCpflList)) {
                cpflPicker.setPicker(mCpflList);
                cpflPicker.show();
            }
        } else if (id == R.id.ll_gx) {      /**选择异常工序*/
            if (10001 == cpflID) {
                showToast("请选择产品分类");
                return;
            }
            HttpParams params = new HttpParams();
            params.put("productType", cpflID);
            OkGoUtils.getInstance().post(EpairDetailsActivity.this, URL.PROCESS_LIST, params, 2, false, mCallback);
        } else if (id == R.id.ll_yclx) {      /**选择异常类型*/
            if (ObjectUtils.notEmpty(mYclxList)) {
                yclxPicker.setPicker(mYclxList);
                yclxPicker.show();
            }
        } else if (id == R.id.ll_ycdj) {       /**选择异常等级*/
            if (ObjectUtils.notEmpty(mYcdjList)) {
                ycdjPicker.setPicker(mYcdjList);
                ycdjPicker.show();
            }
        } else if (id == R.id.ll_clr) {      /**选择处理人*/
                if (ObjectUtils.notEmpty(departList) && ObjectUtils.notEmpty(staffList)) {
                    clrPicker.setPicker(departList, staffList);
                    clrPicker.show();
                }
        }

    }

    /**
     * 请求返回的处理
     */
    private MyCallback mCallback4 = new MyCallback() {
        @Override
        public void onSuccess(ResponseBean response, int id) {
            if (response.getCode() == 200) {
                showToast("提交成功");
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            } else {
                showToast(response.getMsg());
            }
        }

        @Override
        public void onError(Throwable e, int id) {
        }
    };

    /*底部第一个按钮点击事件*/
    public void onSubmit(View view) {
        params = new HttpParams();
        switch (code) {
            case EPAIR_ADD:  //新增
                String sbbh = mEtSbbh.getText().toString();
                String scpc = mEtScpc.getText().toString();
                String zzpbh = mEtZzpbh.getText().toString();
                String ycms = mEtYcms.getText().toString();

                if (sbbh.isEmpty()) {
                    showToast("请输入设备编号");
                    return;
                }

                if (0 == list.size()) {
                    showToast("请输入正确设备编号");
                    return;
                }

                if (10001 == cpflID) {
                    showToast("请选择产品分类");
                    return;
                }
                if (10001 == gxID) {
                    showToast("请选择工序");
                    return;
                }
                if (10001 == yclxID) {
                    showToast("请选择异常类型");
                    return;
                }
                if (10001 == ycdjID) {
                    showToast("请选择异常等级");
                    return;
                }
                if (10001 == clrID) {
                    showToast("请选择处理人");
                    return;
                }

                String yclx = mTvYclx.getText().toString();
                String ycmc = mTvYcmc.getText().toString();

                params.put("fmmProcessOid", gxID); //工序编号
                params.put("proBatchId", scpc); //生产批次
                params.put("productId", zzpbh); //在制品编号
                params.put("equipId", oid); //设备编号
                params.put("prodAnoType", yclx); //异常类型
                //  params.put("prodAnoTName", ycmc); //异常名称
                params.put("prodAnoTGrand", ycdjID); //异常等级
                params.put("userId", clrID); //处理人id
                params.put("prodAnoTDetail", ycms); //异常描述
                params.put("fUserCreator", userId); //创始人id
                params.put("productType", cpflID); //产品分类

                str = Joiner.on(",").join(imagePath);
                params.put("imageUrl", str); //图片 多张图片逗号隔开
                LogUtils.e("lac===========" + yclx);
                LogUtils.e("lac===========" + ycdjID);
                LogUtils.e("lac===========" + clrID);
                LogUtils.e("lac===========" + cpflID);
                OkGoUtils.getInstance().post(EpairDetailsActivity.this, URL.ADD_ABNORMA, params, 5, true, mCallback4);

               /* HttpParams params = new HttpParams();
                params.put("equipID", sbbh);
                OkGoUtils.getInstance().post(this,URL.EFFECT_EQUIPID,params,4,true,mCallback4);*/
                break;
            case EPAIR_DISPOSE: //处理
                String clff = mEtClff.getText().toString();
                String ycyy = mEtYcyy.getText().toString();
                String gjjy = mEtGjjy.getText().toString();
                String bhyy = mEtBhyy.getText().toString();

                if (clff.isEmpty()) {
                    showToast("请输入处理方法");
                    return;
                }

                if (ycyy.isEmpty()) {
                    showToast("请输入异常原因");
                    return;
                }
                params.put("oid", abnormalId); //oid
                params.put("equipId", equipId); //设备编号
                params.put("button", "1"); //按钮 1 处理 2驳回 3确认 4终止
                params.put("fUserUpdate", userId); //更新人ID
                params.put("OptimisticLockField", optimisticLockField); //互锁校验
                params.put("methodDescription", clff); //处理方法
                params.put("prodAnoReason", ycyy); //异常原因
                params.put("suggest", gjjy); //改进建议
                params.put("productType", productType); //驳回原因
                OkGoUtils.getInstance().post(this, URL.HANDLE_ABNORMA, params, 5, true, mCallback4);
                break;
            case EPAIR_AFFIRM: //异常确认
                String cxsj = mEtCxsj.getText().toString();

                if (cxsj.isEmpty()) {
                    showToast("请输入持续时间");
                    return;
                }

                params.put("oid", abnormalId); //oid
                params.put("equipId", equipId); //设备编号
                params.put("button", "3"); //按钮 1 处理 2驳回 3确认 4终止
                params.put("fUserUpdate", userId); //更新人ID
                params.put("OptimisticLockField", optimisticLockField); //互锁校验
                params.put("lastTime", cxsj); //持续时间
                params.put("productType", productType); //驳回原因

                OkGoUtils.getInstance().post(this, URL.HANDLE_ABNORMA, params, 5, true, mCallback4);
                break;
            case REJECT_DISPOSE: //驳回处理 再次提交按钮
                String sbbh2 = mEtSbbh.getText().toString();
                String scpc2 = mEtScpc.getText().toString();
                String zzpbh2 = mEtZzpbh.getText().toString();
                String ycms2 = mEtYcms.getText().toString();

                if (sbbh2.isEmpty()) {
                    showToast("请输入设备编号");
                    return;
                }

                if (0 == list.size()) {
                    showToast("请输入正确设备编号");
                    return;
                }
                if (10001 == gxID) {
                    showToast("请选择工序");
                    return;
                }
                if (10001 == ycdjID) {
                    showToast("请选择异常等级");
                    return;
                }
                if (10001 == clrID) {
                    showToast("请选择处理人");
                    return;
                }

                String yclx2 = mTvYclx.getText().toString();
                String ycmc2 = mTvYcmc.getText().toString();


                params.put("fmmProcessOid", gxID); //工序编号
                params.put("proBatchId", scpc2); //生产批次
                params.put("productId", zzpbh2); //在制品编号
                params.put("prodAnoType", yclx2); //异常类型
                //     params.put("prodAnoTName", ycmc2); //异常名称
                params.put("prodAnoTGrand", ycdjID); //异常等级
                params.put("userId", clrID); //处理人id
                params.put("prodAnoTDetail", ycms2); //异常描述
                params.put("oid", abnormalId); //oid
                params.put("equipId", equipId); //设备编
                params.put("button", "5"); //按钮 1 处理 2驳回 3确认 4终止 5.驳回处理
                params.put("fUserUpdate", userId); //更新人ID
                params.put("OptimisticLockField", optimisticLockField); //互锁校验
                params.put("productType", productType); //驳回原因

                for (int i = 0; i < imagePath.size(); i++) {
                    LogUtils.e("888888lac===========" + imagePath.get(i));
                }
                str = Joiner.on(",").join(imagePath);
                params.put("imageUrl", str); //图片 多张图片逗号隔开
                LogUtils.e("lac===========" + str);
                OkGoUtils.getInstance().post(EpairDetailsActivity.this, URL.HANDLE_ABNORMA, params, 5, true, mCallback4);
                break;
        }
    }

    /*底部第二个按钮单击事件*/
    public void onSubmit2(View view) {
        HttpParams params = new HttpParams();
        switch (code) {
            case EPAIR_DISPOSE: //异常处理 驳回按钮
                String bhyy = mEtBhyy.getText().toString();

                if (bhyy.isEmpty()) {
                    showToast("请输入驳回原因");
                    return;
                }
                params.put("oid", abnormalId); //oid
                params.put("equipId", equipId); //设备编号
                params.put("button", "2"); //按钮 1 处理 2驳回 3确认 4终止
                params.put("fUserUpdate", userId); //更新人ID
                params.put("OptimisticLockField", optimisticLockField); //互锁校验
                params.put("reasonRejection", bhyy); //驳回原因
                params.put("productType", productType); //驳回原因

                LogUtils.e("00=====" + abnormalId);
                LogUtils.e("00=====" + equipId);
                LogUtils.e("00=====" + optimisticLockField);
                OkGoUtils.getInstance().post(this, URL.HANDLE_ABNORMA, params, 5, true, mCallback4);
                break;
            case REJECT_DISPOSE: //驳回处理 中止按钮
                params.put("oid", abnormalId); //oid
                params.put("equipId", equipId); //设备编号
                params.put("button", "4"); //按钮 1 处理 2驳回 3确认 4终止
                params.put("fUserUpdate", userId); //更新人ID
                params.put("OptimisticLockField", optimisticLockField); //互锁校验
                params.put("productType", productType); //驳回原因
                //params.put("reasonRejection", bhyy); //驳回原因

                LogUtils.e("00=====" + abnormalId);
                LogUtils.e("00=====" + equipId);
                LogUtils.e("00=====" + optimisticLockField);
                OkGoUtils.getInstance().post(this, URL.HANDLE_ABNORMA, params, 5, true, mCallback4);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 处理二维码扫描结果
         */
        if (requestCode == REQUEST_CODE_SCPC) {
            //处理扫描结果（在界面上显示）
            onProcessScanResults(REQUEST_CODE_SCPC, data);
        } else if (requestCode == REQUEST_CODE_ZZPBH) {
            onProcessScanResults(REQUEST_CODE_ZZPBH, data);
        } else if (requestCode == REQUEST_CODE_SBBH) {
            onProcessScanResults(REQUEST_CODE_SBBH, data);
        }
    }

    public void onProcessScanResults(int request_code, @Nullable Intent data) {
        if (null != data) {
            Bundle bundle = data.getExtras();
            if (bundle == null) {
                return;
            }
            if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                String result = bundle.getString(CodeUtils.RESULT_STRING);
                switch (request_code) {
                    case REQUEST_CODE_SCPC:
                        mEtScpc.setText(result);
                        break;
                    case REQUEST_CODE_ZZPBH:
                        mEtZzpbh.setText(result);
                        break;
                    case REQUEST_CODE_SBBH:
                        mEtSbbh.setText(result);

                        HttpParams params1 = new HttpParams();
                        params1.put("equipID", result);
                        OkGoUtils.getInstance().post(EpairDetailsActivity.this, URL.GET_DETAIL_INFO, params1, 1, false, mCallback1);
                        break;
                }
            } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                Toast.makeText(EpairDetailsActivity.this, "解析二维码失败", Toast.LENGTH_LONG).show();
            }
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            //当isShouldHideInput(v, ev)为true时，表示的是点击输入框区域，则需要显示键盘，同时显示光标，反之，需要隐藏键盘、光标
            if (ToolUtils.isShouldHideInput(v, ev)) {

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                    //处理Editext的光标隐藏、显示逻辑
                    mEtScpc.clearFocus();
                    mEtZzpbh.clearFocus();
                    mEtSbbh.clearFocus();
                    mEtYcms.clearFocus();
                    mEtClff.clearFocus();
                    mEtYcyy.clearFocus();
                    mEtGjjy.clearFocus();
                    mEtBhyy.clearFocus();
                    mEtCxsj.clearFocus();
                }
            }
            return super.dispatchTouchEvent(ev);
        }
        // 必不可少，否则所有的组件都不会有TouchEvent了
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }
}
